home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageExtend / ImageExtend.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  11.2 KB  |  497 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.image.MemoryImageSource;
  14. import java.awt.image.PixelGrabber;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18.  
  19. public class ImageExtend extends Applet implements Runnable, MouseListener {
  20.    boolean loaded;
  21.    Thread thread;
  22.    Image image;
  23.    Image buffer;
  24.    // $FF: renamed from: b java.awt.Graphics
  25.    Graphics field_0;
  26.    Color backColor;
  27.    // $FF: renamed from: wi int
  28.    int field_1;
  29.    // $FF: renamed from: he int
  30.    int field_2;
  31.    int wiIm;
  32.    int heIm;
  33.    int pause = 20;
  34.    static int[] pix;
  35.    static int[] pixnew;
  36.    // $FF: renamed from: f6 float
  37.    float field_3 = 0.0F;
  38.    // $FF: renamed from: f7 float
  39.    float field_4 = 1.0F;
  40.    // $FF: renamed from: f8 float
  41.    float field_5 = 0.0F;
  42.    // $FF: renamed from: f9 float
  43.    float field_6 = 1.0F;
  44.    float f6Step = 0.05F;
  45.    float f7Step = -0.1F;
  46.    float f8Step = 0.05F;
  47.    float f9Step = -0.1F;
  48.    private String statusBarText;
  49.    private AudioClip sound;
  50.    private AudioClip clicSound;
  51.    private AudioClip enterSound;
  52.    private boolean loopSound;
  53.    private String link;
  54.    // $FF: renamed from: fm java.awt.FontMetrics
  55.    private FontMetrics field_7;
  56.    private String enterText;
  57.    private boolean isEnterTextEnabled;
  58.    private int wiEnterText;
  59.    private int enterTextHeight;
  60.    private Color enterTextColor;
  61.    private int decx;
  62.    private int decy;
  63.  
  64.    public String getAppletInfo() {
  65.       return "Name: ImageExtend\r\nAuthor: Taiji Software\r\n";
  66.    }
  67.  
  68.    public ImageExtend() {
  69.       this.f6Step = 0.05F;
  70.       this.f7Step = -0.1F;
  71.       this.f8Step = 0.05F;
  72.       this.f9Step = -0.1F;
  73.       this.backColor = Color.black;
  74.       ((Component)this).addMouseListener(this);
  75.    }
  76.  
  77.    public void register() {
  78.       try {
  79.          URL u = new URL("http://www.taijisoftware.com");
  80.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  81.          this.stop();
  82.       } catch (Exception e) {
  83.          System.out.println(e);
  84.          this.stop();
  85.       }
  86.    }
  87.  
  88.    public void init() {
  89.       String codeBase = null;
  90.  
  91.       try {
  92.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  93.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  94.          codeBase = codeBase.toUpperCase();
  95.       } catch (Exception var11) {
  96.       }
  97.  
  98.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  99.          String regCode = ((Applet)this).getParameter("registration_code");
  100.          if (regCode == null) {
  101.             regCode = ((Applet)this).getParameter("reg_domain");
  102.             if (regCode == null) {
  103.                this.register();
  104.             } else {
  105.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  106.                   codeBase = "WWW." + codeBase;
  107.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  108.                   codeBase = codeBase.substring(4);
  109.                }
  110.  
  111.                char[] chars = new char[codeBase.length()];
  112.                codeBase.getChars(0, codeBase.length(), chars, 0);
  113.                String key = new String("haricot");
  114.                char[] chars2 = new char[key.length()];
  115.                key.getChars(0, key.length(), chars2, 0);
  116.  
  117.                for(int i = 0; i < codeBase.length(); ++i) {
  118.                   int j;
  119.                   if (i >= key.length()) {
  120.                      j = i - key.length() * (i / key.length());
  121.                   } else {
  122.                      j = i;
  123.                   }
  124.  
  125.                   chars[i] += chars2[j];
  126.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  127.                }
  128.  
  129.                String res = new String(chars);
  130.                if (!res.equalsIgnoreCase(regCode)) {
  131.                   this.register();
  132.                }
  133.             }
  134.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  135.             this.register();
  136.          }
  137.       }
  138.  
  139.       this.getParameters();
  140.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  141.       MediaTracker tracker = new MediaTracker(this);
  142.       tracker.addImage(this.image, 0);
  143.  
  144.       try {
  145.          tracker.waitForAll();
  146.          tracker.isErrorAny();
  147.       } catch (Exception e) {
  148.          System.err.println(e);
  149.       }
  150.  
  151.       if (!this.loaded) {
  152.          this.stop();
  153.       }
  154.  
  155.       this.wiIm = this.image.getWidth(this);
  156.       this.heIm = this.image.getHeight(this);
  157.       pix = new int[this.wiIm * this.heIm];
  158.       pixnew = new int[this.wiIm * this.heIm];
  159.       this.decx = (this.field_1 - this.wiIm) / 2;
  160.       this.decy = (this.field_2 - this.heIm) / 2;
  161.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  162.  
  163.       try {
  164.          pixg.grabPixels();
  165.       } catch (InterruptedException var9) {
  166.       }
  167.  
  168.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  169.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  170.       this.field_0 = this.buffer.getGraphics();
  171.       this.field_0.setColor(this.enterTextColor);
  172.       String fontName = ((Applet)this).getParameter("enter_text_font");
  173.       if (fontName == null) {
  174.          fontName = "TimesRoman";
  175.       }
  176.  
  177.       int style = 1;
  178.       String s = ((Applet)this).getParameter("enter_text_style");
  179.       if (s != null) {
  180.          if (s.equals("bold")) {
  181.             style = 1;
  182.          } else if (s.equals("italic")) {
  183.             style = 2;
  184.          } else if (s.equals("bold_italic")) {
  185.             style = 3;
  186.          } else {
  187.             style = 0;
  188.          }
  189.       }
  190.  
  191.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  192.       this.field_7 = this.field_0.getFontMetrics();
  193.       if (this.enterText != null) {
  194.          this.wiEnterText = this.field_7.stringWidth(this.enterText);
  195.       }
  196.  
  197.       if (this.sound != null) {
  198.          if (this.loopSound) {
  199.             this.sound.loop();
  200.             return;
  201.          }
  202.  
  203.          this.sound.play();
  204.       }
  205.  
  206.    }
  207.  
  208.    public void getParameters() {
  209.       this.field_1 = ((Component)this).getSize().width;
  210.       this.field_2 = ((Component)this).getSize().height;
  211.       String s = ((Applet)this).getParameter("pause");
  212.       if (s != null) {
  213.          this.pause = Integer.parseInt(s);
  214.       }
  215.  
  216.       s = ((Applet)this).getParameter("topLeftCorner");
  217.       if (s != null) {
  218.          this.field_3 = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  219.       }
  220.  
  221.       s = ((Applet)this).getParameter("topRightCorner");
  222.       if (s != null) {
  223.          this.field_4 = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  224.       }
  225.  
  226.       s = ((Applet)this).getParameter("bottomRightCorner");
  227.       if (s != null) {
  228.          this.field_5 = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  229.       }
  230.  
  231.       s = ((Applet)this).getParameter("bottomLeftCorner");
  232.       if (s != null) {
  233.          this.field_6 = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  234.       }
  235.  
  236.       s = ((Applet)this).getParameter("topLeftStep");
  237.       if (s != null) {
  238.          this.f6Step = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  239.       }
  240.  
  241.       s = ((Applet)this).getParameter("topRightStep");
  242.       if (s != null) {
  243.          this.f7Step = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  244.       }
  245.  
  246.       s = ((Applet)this).getParameter("bottomRightStep");
  247.       if (s != null) {
  248.          this.f8Step = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  249.       }
  250.  
  251.       s = ((Applet)this).getParameter("bottomLeftStep");
  252.       if (s != null) {
  253.          this.f9Step = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  254.       }
  255.  
  256.       this.backColor = this.getColor("background_color");
  257.       ((Component)this).setBackground(this.backColor);
  258.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  259.       s = ((Applet)this).getParameter("sound_name");
  260.       if (s != null) {
  261.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  262.       }
  263.  
  264.       s = ((Applet)this).getParameter("loop_sound");
  265.       if (s != null) {
  266.          if (s.equals("yes")) {
  267.             this.loopSound = true;
  268.          } else {
  269.             this.loopSound = false;
  270.          }
  271.       }
  272.  
  273.       s = ((Applet)this).getParameter("clic_sound_name");
  274.       if (s != null) {
  275.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  276.       }
  277.  
  278.       s = ((Applet)this).getParameter("enter_sound_name");
  279.       if (s != null) {
  280.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  281.       }
  282.  
  283.       this.link = ((Applet)this).getParameter("link");
  284.       this.enterText = ((Applet)this).getParameter("enter_text");
  285.       s = ((Applet)this).getParameter("enter_text_height");
  286.       if (s != null) {
  287.          this.enterTextHeight = Integer.parseInt(s);
  288.       }
  289.  
  290.       this.enterTextColor = this.getColor("enter_text_color");
  291.       if (this.enterTextColor == null) {
  292.          this.enterTextColor = Color.white;
  293.       }
  294.  
  295.    }
  296.  
  297.    public Color getColor(String param) {
  298.       String s = ((Applet)this).getParameter(param);
  299.       if (s != null) {
  300.          if (s.substring(0, 1).equals("#")) {
  301.             s = s.substring(1);
  302.             int i = Integer.parseInt(s, 16);
  303.             return new Color(i);
  304.          } else {
  305.             return null;
  306.          }
  307.       } else {
  308.          return null;
  309.       }
  310.    }
  311.  
  312.    public void start() {
  313.       if (this.thread == null) {
  314.          this.thread = new Thread(this);
  315.          this.thread.start();
  316.       }
  317.  
  318.    }
  319.  
  320.    public void stop() {
  321.       if (this.thread != null) {
  322.          this.thread = null;
  323.       }
  324.  
  325.       if (this.sound != null) {
  326.          this.sound.stop();
  327.       }
  328.  
  329.    }
  330.  
  331.    public void run() {
  332.       Thread.currentThread().setPriority(4);
  333.  
  334.       while(true) {
  335.          ((Component)this).repaint();
  336.  
  337.          try {
  338.             Thread.sleep((long)this.pause);
  339.          } catch (InterruptedException var1) {
  340.          }
  341.  
  342.          this.calculatePixels();
  343.          this.field_3 += this.f6Step;
  344.          if (this.field_3 > 1.0F || this.field_3 < 0.0F) {
  345.             this.f6Step = -this.f6Step;
  346.          }
  347.  
  348.          this.field_4 += this.f7Step;
  349.          if (this.field_4 > 1.0F || this.field_4 < 0.0F) {
  350.             this.f7Step = -this.f7Step;
  351.          }
  352.  
  353.          this.field_5 += this.f8Step;
  354.          if (this.field_5 > 1.0F || this.field_5 < 0.0F) {
  355.             this.f8Step = -this.f8Step;
  356.          }
  357.  
  358.          this.field_6 += this.f9Step;
  359.          if (this.field_6 > 1.0F || this.field_6 < 0.0F) {
  360.             this.f9Step = -this.f9Step;
  361.          }
  362.       }
  363.    }
  364.  
  365.    public final void paint(Graphics g) {
  366.       if (!this.loaded) {
  367.          this.field_0.setColor(Color.white);
  368.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  369.          this.loaded = true;
  370.       } else {
  371.          if (this.image != null) {
  372.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  373.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  374.             if (this.isEnterTextEnabled) {
  375.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  376.             }
  377.  
  378.             this.image = null;
  379.          }
  380.  
  381.          g.drawImage(this.buffer, 0, 0, this);
  382.       }
  383.    }
  384.  
  385.    public final void update(Graphics g) {
  386.       this.paint(g);
  387.    }
  388.  
  389.    private final void calculatePixels() {
  390.       int w2 = this.wiIm / 2;
  391.       int h2 = this.heIm / 2;
  392.  
  393.       for(int ii = 0; ii < this.heIm; ++ii) {
  394.          for(int jj = 0; jj < this.wiIm; ++jj) {
  395.             float r1 = this.field_3 + (float)jj * (this.field_4 - this.field_3) / (float)this.wiIm;
  396.             float r2 = this.field_6 + (float)ii * (this.field_5 - this.field_6) / (float)this.heIm;
  397.             float r3 = (float)(jj - h2) / r2 + (float)h2;
  398.             float r4 = (float)(ii - w2) / r1 + (float)w2;
  399.             if (r3 > 0.0F && r3 < (float)(this.wiIm - 1) && r4 > 0.0F && r4 < (float)(this.heIm - 1)) {
  400.                float r5 = r3 - (float)((int)r3);
  401.                float r6 = r4 - (float)((int)r4);
  402.                int i = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 16711680, 16) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 16711680, 16) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 16711680, 16) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 16711680, 16));
  403.                int j = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 65280, 8) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 65280, 8) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 65280, 8) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 65280, 8));
  404.                int k = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 255, 0) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 255, 0) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 255, 0) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 255, 0));
  405.                pixnew[ii * this.wiIm + jj] = (new Color(i, j, k)).getRGB();
  406.             } else {
  407.                pixnew[ii * this.wiIm + jj] = this.backColor.getRGB();
  408.             }
  409.          }
  410.       }
  411.  
  412.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  413.    }
  414.  
  415.    public final int pixel(int i, int j, int hex, int dec) {
  416.       return (pix[i * this.wiIm + j] & hex) >> dec;
  417.    }
  418.  
  419.    public URL giveURL(String url) {
  420.       try {
  421.          if (url.toUpperCase().startsWith("HTTP")) {
  422.             return new URL(url);
  423.          } else if (url.toUpperCase().startsWith("FTP")) {
  424.             int p = url.indexOf(":");
  425.             int p2 = url.indexOf(":", p + 1);
  426.             if (p2 != -1) {
  427.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  428.             }
  429.  
  430.             p = url.indexOf("%40");
  431.             if (p != -1) {
  432.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  433.             }
  434.  
  435.             return new URL(url);
  436.          } else {
  437.             return new URL(((Applet)this).getCodeBase(), url);
  438.          }
  439.       } catch (MalformedURLException e) {
  440.          System.out.println(e);
  441.          return null;
  442.       }
  443.    }
  444.  
  445.    public void mouseClicked(MouseEvent e) {
  446.    }
  447.  
  448.    public void mouseEntered(MouseEvent e) {
  449.       if (this.clicSound != null) {
  450.          this.clicSound.play();
  451.       }
  452.  
  453.       if (this.link != null) {
  454.          String target = ((Applet)this).getParameter("target");
  455.          if (target == null) {
  456.             target = "_blank";
  457.          }
  458.  
  459.          URL u = this.giveURL(this.link);
  460.          ((Applet)this).getAppletContext().showDocument(u, target);
  461.       }
  462.  
  463.    }
  464.  
  465.    public void mouseExited(MouseEvent e) {
  466.       if (this.isEnterTextEnabled) {
  467.          this.isEnterTextEnabled = false;
  468.          ((Component)this).repaint();
  469.       }
  470.  
  471.       if (this.link != null) {
  472.          ((Component)this).setCursor(new Cursor(0));
  473.       }
  474.  
  475.    }
  476.  
  477.    public void mousePressed(MouseEvent e) {
  478.       if (this.clicSound != null) {
  479.          this.clicSound.play();
  480.       }
  481.  
  482.       if (this.link != null) {
  483.          String target = ((Applet)this).getParameter("target");
  484.          if (target == null) {
  485.             target = "_blank";
  486.          }
  487.  
  488.          URL u = this.giveURL(this.link);
  489.          ((Applet)this).getAppletContext().showDocument(u, target);
  490.       }
  491.  
  492.    }
  493.  
  494.    public void mouseReleased(MouseEvent e) {
  495.    }
  496. }
  497.